package kr.or.kosta.otr.service.adminservice;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;

import javax.annotation.Resource;

import kr.or.kosta.otr.persistence.admin.AdminDao;
import kr.or.kosta.otr.persistence.company.CompanyDao;
import kr.or.kosta.otr.persistence.industry.IndustryDao;
import kr.or.kosta.otr.persistence.mentor.MentorDao;
import kr.or.kosta.otr.persistence.message.MessageDao;
import kr.or.kosta.otr.persistence.messagetype.MessageTypeDao;
import kr.or.kosta.otr.persistence.notice.NoticeDao;
import kr.or.kosta.otr.persistence.profession.ProfessionDao;
import kr.or.kosta.otr.persistence.region.RegionDao;
import kr.or.kosta.otr.persistence.user.UserDao;
import kr.or.kosta.otr.utill.NoticeListVO;
import kr.or.kosta.otr.utill.PagingBean;
import kr.or.kosta.otr.vo.CompanyVO;
import kr.or.kosta.otr.vo.IndustryVO;
import kr.or.kosta.otr.vo.MentorVO;
import kr.or.kosta.otr.vo.MessageTypeVO;
import kr.or.kosta.otr.vo.MessageVO;
import kr.or.kosta.otr.vo.NoticeVO;
import kr.or.kosta.otr.vo.ProfessionVO;
import kr.or.kosta.otr.vo.RegionVO;
import kr.or.kosta.otr.vo.UserVO;

import org.springframework.stereotype.Service;

@Service("AdminService")
public class AdminServiceImpl implements AdminService{
	
	@Resource(name="AdminDao")
	private AdminDao adminDao;
	
	@Resource(name="CompanyDao")
	private CompanyDao companyDao;
	
	@Resource(name="IndustryDao")
	IndustryDao industryDao;
	
	@Resource(name="RegionDao")
	RegionDao regionDao;
	
	@Resource(name="NoticeDao")
	NoticeDao noticeDao;

	@Resource(name="ProfessionDao")
	ProfessionDao professionDao;
	
	@Resource(name="MessageTypeDao")
	MessageTypeDao messageTypeDao;
	
	@Resource(name="MessageDao")
	MessageDao messageDao;
	
	@Resource(name="MentorDao")
	MentorDao mentorDao;
	
	@Resource(name="UserDao")
	UserDao userDao;
	
	@Override
	public void addCompany(CompanyVO vo) throws SQLException{
		companyDao.addCompany(vo);
	}
	

	@Override
	public ArrayList<CompanyVO> getCompanyInfo(HashMap<String, Object> map)
			throws SQLException {
		
		return companyDao.getCompanyInfo(map);
	}


	@Override
	public IndustryVO getIndustry(HashMap<String, Object> map)
			throws SQLException {
		
		return industryDao.getIndustry(map);
	}


	@Override
	public RegionVO getRegion(HashMap<String, Object> map) throws SQLException {
		
		return regionDao.getRegion(map);
	}


	@Override
	public void deleteCompany(int companyId) throws SQLException {
		companyDao.deleteCompany(companyId);
		
	}


	@Override
	public CompanyVO getOneCompany(int companyId) throws SQLException {
		
		return companyDao.getOneCompany(companyId);
	}


	@Override
	public void updateCompany(CompanyVO vo) throws SQLException {
		companyDao.updateCompany(vo);
		
	}
	
	@Override
	public NoticeVO writeNotice(NoticeVO vo) throws SQLException {
		int noticeId=noticeDao.writeNotice(vo);
		NoticeVO rvo=noticeDao.getOneNotice(noticeId);
		rvo.getAdminVo().setAdminPassword(null);
		rvo.getAdminVo().setAdminEmail(null);
		rvo.getAdminVo().setAdminPhone(0);
		return rvo;
	}

	@Override
	public void updateNotice(NoticeVO vo) throws SQLException {
		noticeDao.updateNotice(vo);
	}

	@Override
	public void deleteNotice(int noticeId) throws SQLException {
		noticeDao.deleteNotice(noticeId);
	}

	@Override
	public NoticeVO getOneNotice(int noticeId) throws SQLException {
		noticeDao.updateHit(noticeId);
		NoticeVO vo=noticeDao.getOneNotice(noticeId);
		vo.getAdminVo().setAdminPassword(null);
		vo.getAdminVo().setAdminEmail(null);
		vo.getAdminVo().setAdminPhone(0);
		return vo;
	}

	@Override
	public ArrayList<NoticeVO> getAllNotice() throws SQLException {
		return noticeDao.getAllNotice();
	}
	
	@Override
	public NoticeListVO getNoticeListByPage(String pageNo) throws SQLException {
		int pn=1;
		
		if(pageNo!=null){
			pn=Integer.parseInt(pageNo);
		}
		
		ArrayList<NoticeVO> list=noticeDao.getNoticeListByPage(pn);
		int totalContents=noticeDao.getTotalCount();
		PagingBean pb=new PagingBean(totalContents, pn);
		
		return new NoticeListVO(list, pb);
	}


	@Override
	public ArrayList<CompanyVO> getAllCompany() throws SQLException {
		 
		return companyDao.getAllCompany();
	}

	@Override
	public ArrayList<IndustryVO> getAllIndustry() throws SQLException {
		
		return industryDao.getAllIndustry();
	}

	@Override
	public ArrayList<ProfessionVO> getAllProfession() throws SQLException {
		
		return professionDao.getAllProfession();
	}

	@Override
	public ArrayList<RegionVO> getAllRegion() throws SQLException {
		
		return regionDao.getAllRegion();
	}


	@Override
	public CompanyVO checkCompany(HashMap<String, String> map)
			throws SQLException {
		
		return companyDao.checkCompany(map);
	}
	

	@Override
	public ArrayList<MessageTypeVO> getAllMessageType() throws SQLException {
		
		return messageTypeDao.getAllMessageType();
	}

	@Override
	public MessageTypeVO getMessageType(HashMap<String, Object> map) throws SQLException {
		
		return messageTypeDao.getMessageType(map);
	}

	@Override
	public void writeMessage(MessageVO vo) throws SQLException {
		messageDao.writeMessage(vo);
		
	}


	@Override
	public void addMentor(MentorVO vo) throws SQLException {
		// TODO Auto-generated method stub
		mentorDao.addMentor(vo);
	}


	@Override
	public CompanyVO getOneCompanyByName(String companyName)
			throws SQLException {
		// TODO Auto-generated method stub
		return companyDao.getOneCompanyByName(companyName);
	}


	@Override
	public boolean isExist(String userId) throws SQLException {
		// TODO Auto-generated method stub
		return userDao.isExist(userId);
	}


	@Override
	public int isExistMentor(HashMap<String, Object> map) throws SQLException {
		// TODO Auto-generated method stub
		return mentorDao.isExistMentor(map);
	}


	@Override
	public ArrayList<UserVO> getAllUser(String adminId) throws SQLException {
		
		return userDao.getAllUser(adminId);
	}


	@Override
	public void deleteUser(String userId) throws SQLException {
		userDao.deleteUser(userId);
		
	}

	@Override
	public ArrayList<UserVO> getOneUserByUserId(HashMap<String, String> map)
			throws SQLException {
	
		return userDao.getOneUserByUserId(map);
	}


	@Override
	public ArrayList<MentorVO> getAllMentor(HashMap<String, Object> map)
			throws SQLException {
		
		return mentorDao.getAllMentor(map);
	}


	@Override
	public void updatePointMinus(HashMap<String, Object> map)
			throws SQLException {
		userDao.updatePointMinus(map);
		
	}


	@Override
	public void deleteMentor(int mentorId) throws SQLException {
		mentorDao.deleteMentor(mentorId);
		
	}

}
